import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;

import CustomSprite;
import Button;
import Images;
import PopUpText;

class WallStreetMenuEvent extends Event{
public var Number:String;
	public function new(customEventString:String,inNumber:String){
	Number = inNumber;
	super(customEventString, true, false);

    }
}

class WallStreetMenu extends GenericMenu
{
public var SmallBusiness:Button;
public var MediumBusiness:Button;
public var LargeBusiness:Button;
public var StockMarket:Button;
public var FindJob:Button;
public var Description:TextField;
private var currentDescription:String;
public var OkPopUpText : PopUpText;
public var popUpState : String;
public var  buttonSprite : Sprite;
public var  background : Sprite;

public function new(inBackground:BitmapData) {
     super(inBackground);
    this.graphics.clear();
    this.removeChild(BackButton);
    background = new Sprite();
     background.graphics.clear();
      background.graphics.beginFill(0xFFFFFF);
      //Grid.graphics.drawRect(0, 0,620-150,472);
      background.graphics.drawRect(0,0,640,472);
      background.graphics.endFill();
      background.alpha =0.5;
      buttonSprite = new Sprite();
      buttonSprite.graphics.beginFill(0x000000);
      //Grid.graphics.drawRect(0, 0,620-150,472);
      buttonSprite.graphics.drawRect(0,0,640,Constants.flashHeight-20);
      buttonSprite.graphics.endFill();
      buttonSprite.addChild(BackButton);
  Description = new TextField();
  currentDescription = "Here is where you make Investments";
  Description.htmlText= "<font color='#FFFFFF' size='16'>"+currentDescription+"</font>";
  Description.wordWrap = true;

  buttonSprite.addChild(Description);
  SmallBusiness = new Button(250,50,"Buy A Small Business");
  SmallBusiness.x = 10;
  SmallBusiness.y = 10;
  SmallBusiness.buttonMode = true;
  buttonSprite.addChild(SmallBusiness);
  
  SmallBusiness.addEventListener(MouseEvent.MOUSE_OVER, onSmallBusinessOver);
  SmallBusiness.addEventListener(MouseEvent.CLICK, onSmallBusinessClick);
  SmallBusiness.addEventListener(MouseEvent.MOUSE_OUT, onSmallBusinessOut);

MediumBusiness = new Button(250,50,"Buy A Medium Business");
  MediumBusiness.x = 10;
  MediumBusiness.y = 60;
  MediumBusiness.buttonMode = true;
  buttonSprite.addChild(MediumBusiness);
  
  MediumBusiness.addEventListener(MouseEvent.MOUSE_OVER, onMediumBusinessOver);
  MediumBusiness.addEventListener(MouseEvent.CLICK, onMediumBusinessClick);
  MediumBusiness.addEventListener(MouseEvent.MOUSE_OUT, onMediumBusinessOut);

  LargeBusiness = new Button(250,50,"Buy A Large Business");
  LargeBusiness.x = 10;
  LargeBusiness.y = 110;
  LargeBusiness.buttonMode = true;
  buttonSprite.addChild(LargeBusiness);
  
  LargeBusiness.addEventListener(MouseEvent.MOUSE_OVER, onLargeBusinessOver);
  LargeBusiness.addEventListener(MouseEvent.CLICK, onLargeBusinessClick);
  LargeBusiness.addEventListener(MouseEvent.MOUSE_OUT, onLargeBusinessOut);

  StockMarket = new Button(250,50,"Invest");
  StockMarket.x = 10;
  StockMarket.y = 160;
  StockMarket.buttonMode = true;
  buttonSprite.addChild(StockMarket);
  
  StockMarket.addEventListener(MouseEvent.MOUSE_OVER, onStockMarketOver);
  StockMarket.addEventListener(MouseEvent.CLICK, onStockMarketClick);
  StockMarket.addEventListener(MouseEvent.MOUSE_OUT, onStockMarketOut);
  this.addEventListener("PopUpTextEvent",onPopUpTextEvent);

  //addChild(Description);
  FindJob = new Button(250,50,"Find A Job");
  FindJob.x = 10;
  FindJob.y = 210;
  FindJob.buttonMode = true;
  buttonSprite.addChild(FindJob);
  
  FindJob.addEventListener(MouseEvent.MOUSE_OVER, onFindJobOver);
  FindJob.addEventListener(MouseEvent.CLICK, onFindJobClick);
  FindJob.addEventListener(MouseEvent.MOUSE_OUT, onFindJobOut);


  OkPopUpText = new PopUpText(inBackground.clone(),"<font color='#FFFFFF'>Enter Amount To Invest</font>",0x000000,0xFFFFFF);
      //OkPopUpText.graphics.clear();
      //OkPopUpText.graphics.beginFill(0x000000);
      //Grid.graphics.drawRect(0, 0,620-150,472);
      //OkPopUpText.graphics.drawRect(0,0,640,Constants.flashHeight-20);
      //OkPopUpText.graphics.endFill();
      

  var myFormat:TextFormat = new TextFormat();
  //myFormat.size = 15;
  Description.autoSize = TextFieldAutoSize.CENTER;
  Description.x = 405;
  Description.y = (height-32) / 2 + 75;
  Description.width=230;
  
  
  Description.selectable = false;
  Description.mouseEnabled = false;
  addChild(background);
  addChild(buttonSprite);

  }

private function onFindJobClick(event:MouseEvent){
  dispatchEvent(new WallStreetMenuEvent("FindJob","-1"));
}
private function onFindJobOver(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+"Find A Job. Shortkey F"+"</font>";
}

private function onFindJobOut(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+currentDescription+"</font>";
}

private function onSmallBusinessClick(event:MouseEvent){
  dispatchEvent(new WallStreetMenuEvent("ignoreKeyPress","-1"));
  popUpState = "SmallBusiness";
   addChild(OkPopUpText);
   OkPopUpText.text.htmlText = "<font color ='#FFFFFF'>Enter Number of Small Businesses to Buy</font>";
    OkPopUpText.Load();
}
private function onSmallBusinessOver(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+"Small Business Costs $10,000 and produces $200/week. Shortkey 1"+"</font>";
}

private function onSmallBusinessOut(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+currentDescription+"</font>";
}
private function onMediumBusinessClick(event:MouseEvent){
    dispatchEvent(new WallStreetMenuEvent("ignoreKeyPress","-1"));
  popUpState = "MediumBusiness";
    addChild(OkPopUpText);
   OkPopUpText.text.htmlText = "<font color='#FFFFFF'>Enter Number of Medium Businesses to Buy</font>";
    OkPopUpText.Load();
}
private function onMediumBusinessOver(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+"Medium Business Costs $100,000 and produces $4,000/week. Shortkey 2"+"</font>";
}

private function onMediumBusinessOut(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+currentDescription+"</font>";
}
private function onLargeBusinessClick(event:MouseEvent){
    dispatchEvent(new WallStreetMenuEvent("ignoreKeyPress","-1"));
  popUpState = "LargeBusiness";
    addChild(OkPopUpText);
   OkPopUpText.text.htmlText = "<font color ='#FFFFFF'>Enter Number of Large Businesses to Buy</font>";
    OkPopUpText.Load();
}
private function onLargeBusinessOver(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+"Medium Business Costs $1,000,000 and produces $80,000/week. Shortkey 3"+"</font>";
}

private function onLargeBusinessOut(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+currentDescription+"</font>";
}

private function onStockMarketClick(event:MouseEvent){
    dispatchEvent(new WallStreetMenuEvent("ignoreKeyPress","-1"));
    popUpState = "StockMarket";
    addChild(OkPopUpText);
    OkPopUpText.text.htmlText = "<font color ='#FFFFFF'>Enter Amount To Invest</font>";
    OkPopUpText.Load();
}
private function onStockMarketOver(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+"Invest Money. Returns are withdrawned after each week and losses are repaid every week. Shortkey I"+"</font>";
}

private function onStockMarketOut(event:MouseEvent) {
 Description.htmlText= "<font color='#FFFFFF' size='16'>"+currentDescription+"</font>";
}

private function onPopUpTextEvent(event:PopUpTextEvent){
  this.removeChild(OkPopUpText);
  if(popUpState == "StockMarket")
  {dispatchEvent(new WallStreetMenuEvent("StockMarket",event.Number));}
else if(popUpState == "SmallBusiness")
  {dispatchEvent(new WallStreetMenuEvent("SmallBusiness",event.Number));}
else if(popUpState == "MediumBusiness")
  {dispatchEvent(new WallStreetMenuEvent("MediumBusiness",event.Number));}
  else if(popUpState == "LargeBusiness")
  {dispatchEvent(new WallStreetMenuEvent("LargeBusiness",event.Number));}this.removeChild(OkPopUpText);
}

}	